<?php

    // 获取前端表格中的各项数据
    $id = $_GET['id'];
    $name = $_GET['name'];
    $price = $_GET['price'];
    $num = $_GET['num'];
    $size = $_GET['size'];

    // 连接数据库
    $conn = mysqli_connect('localhost', 'root', 'root', 'praday01');

    // 设置编码
    mysqli_query($conn, "set charset 'utf8'");
    mysqli_query($conn, "set character set 'utf8'");

    // 设置sql语句
    $sql = "update shop set name='$name', price=$price, num=$num, size='$size' where id=$id";

    // 执行sql语句
    $res = mysqli_query($conn, $sql);
    

    // update执行之后返回布尔值
    if ($res) {
        // 将变量进行json编码
        echo json_encode(array(
            "code" => 200,
            "body" => array(
                "msg" => "修改商品成功"
            )
        ));
    } else {
        echo json_encode(array(
            "code" => 205,
            "body" => array(
                "msg" => "网络错误，修改失败"
            )
        ));
    }

?>